package com.xsp.service.Impl;

import com.xsp.entity.BookInfo;
import com.xsp.service.BookInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xsp
 * @date 2024/1/20
 * @desc
 */
//@Service
public class BookInfoServiceProxy implements BookInfoService {
    public BookInfoServiceProxy() {
    }

    public BookInfoServiceProxy(BookInfoService target) {
        this.target = target;
    }

    @Resource(name = "bookInfoService")
    private BookInfoService target;
    private final Logger logger = LoggerFactory.getLogger(BookInfoServiceProxy.class);

    @Override
    public void addBook(BookInfo bookInfo) {
        logger.debug("代理对象开始工作");
        try{
            // 执行被代理对象的业务方法
            target.addBook(bookInfo);
        } catch(Exception e) {
            e.printStackTrace();
            logger.error("执行新增图书信息时发生了异常：{}",e.getMessage());
            logger.error("发生异常时，新增的图书信息是：{}",bookInfo.toString());
        }

        logger.debug("代理对象结束工作");
    }
}
